package edu.npu.GraphTransform;

import java.io.IOException;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.Partitioner;
import org.apache.hadoop.mapreduce.Reducer;

public class GraphNodeExtract {
	public static class GraphNodeExtractMapper extends
			Mapper<LongWritable, Text, LongWritable, Text> {
		String SEPARATOR = "\t";
		@Override
		protected void map(LongWritable key, Text value, Context context)
				throws IOException, InterruptedException {
			String line = value.toString();
			String[] splits = line.split(SEPARATOR);
			for (String split : splits) {
				long id = Long.parseLong(split);
				context.write(new LongWritable(id), new Text());
			}
		}
	}

	public static class GraphNodeExtractReducer extends
			Reducer<LongWritable, Text, LongWritable, Text> {
		@Override
		protected void reduce(LongWritable key, Iterable<Text> values,
				Context context) throws IOException, InterruptedException {
			context.write(key, new Text());
		}
	}
	
	public static class GraphNodeExtractPartioner extends Partitioner<LongWritable, Text> {
		@Override
		public int getPartition(LongWritable key, Text value, int num) {
			int MAXIMUM = 61580000;
			return (int) (key.get() * num * 1.0 / MAXIMUM);
		}
	}
	
	
}
